/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol;

import com.zsmartsystems.zigbee.IeeeAddress;
import java.util.ArrayList;
import java.util.List;

/**
 * Class to implement the Telegesis command <b>Route Record Message</b>.
 * <p>
 * Route Record Message received
 * <p>
 * This class provides methods for processing Telegesis AT API commands.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class TelegesisRouteRecordMessageEvent extends TelegesisFrame implements TelegesisEvent {
    /**
     * SR response field
     */
    private Integer hops;

    /**
     * SR response field
     */
    private IeeeAddress remoteAddress;

    /**
     * SR response field
     */
    private List<Integer> networkRoute = new ArrayList<Integer>();

    /**
     *
     * @return the hops as {@link Integer}
     */
    public Integer getHops() {
        return hops;
    }

    /**
     *
     * @return the remoteAddress as {@link IeeeAddress}
     */
    public IeeeAddress getRemoteAddress() {
        return remoteAddress;
    }

    /**
     *
     * @return the networkRoute as {@link List} of {@link Integer}
     */
    public List<Integer> getNetworkRoute() {
        return networkRoute;
    }


    @Override
    public void deserialize(int[] data) {
        initialiseDeserializer(data);

        // Deserialize the fields for the "SR" response
        if (testPrompt(data, "SR:")) {
            setDeserializer(3);

            // Deserialize field "hops"
            hops = deserializeInt8();
            stepDeserializer();

            // Deserialize field "remote Address" [optional]
            pushDeserializer();
            remoteAddress = deserializeIeeeAddress();
            if (remoteAddress == null) {
                popDeserializer();
            } else {
                stepDeserializer();
            }

            // Deserialize field "network route"
            while (true) {
                Integer tmpNetworkRoute = deserializeInt16();
                if (tmpNetworkRoute == null) {
                    break;
                }
                stepDeserializer();
                networkRoute.add(tmpNetworkRoute);
            }
        }
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(392);
        builder.append("TelegesisRouteRecordMessageEvent [hops=");
        builder.append(hops);
        builder.append(", remoteAddress=");
        builder.append(remoteAddress);
        builder.append(", networkRoute=");
        builder.append(networkRoute);
        builder.append(']');
        return builder.toString();
    }
}
